﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Antioch.Base
{
	[Jemgine.Engine.Category("Antioch Navigation"), Jemgine.Engine.Component]
	public class LedgeHangPoint : PlayerNavigationNode
	{
        [ContentSerializer(Optional = true)]
        public bool CanClimb { get; set; }

        public LedgeHangPoint()
        {
            CanClimb = true;
        }

        protected override void SetExtents(Jemgine.Math.OBB OBB)
        {
            OBB.Extents = new Vector2(1, 1);
        }

        public bool CanHang(Jemgine.Data.EntityRecord Entity)
        {
            float HangAngle = Jemgine.Math.Angle.Normalize(Angle + Me.Angle);
            float HangAngleDelta = Jemgine.Math.Angle.Delta(Jemgine.Math.Angle.Normalize(Entity.Angle), HangAngle);

            switch (Entity.Facing)
            {
                case Jemgine.Data.Facings.Left:
                    if (HangAngleDelta <= System.Math.PI * 0.65f) return false;
                    if (HangAngleDelta > System.Math.PI * 0.85f) return false;
                    break;
                case Jemgine.Data.Facings.Right:
                    if (HangAngleDelta >= -System.Math.PI * 0.65f) return false;
                    if (HangAngleDelta < -System.Math.PI * 0.85f) return false;
                    break;
            }
            return true;
        }
    }

 
}
